import tui from '@/common/tui.js'

//支付（bytedance ali+zhifubao）
export const setPay = function(payInfo, callback) {
	let httpUrl = "/pay/pay/bytedance/per/api/pay";
	tui.tGetAction(httpUrl, {
		orderNo: payInfo
	}).then(data => {
		console.log("后端下单后返回的数据data"+JSON.stringify(data))
		let payData = {
			success: function(res) {
				callback && callback({
					success: true,
					data: res
				});
				console.log('success:' + JSON.stringify(res));
			},
			fail: function(err) {
				callback && callback({
					success: false,
					data: err
				});
				console.log('fail:' + JSON.stringify(err));
			}
		};
		if (payInfo.type == 'wxpay') {
			// app微信
			payData.provider = 'wxpay';
			payData.orderInfo = data;
		} else if (payInfo.type == 'alipay') {
			// app 支付宝
			payData.provider = 'alipay';
			payData.orderInfo = data;
		} else if (payInfo.type == 'baidu') {
			payData.provider = 'baidu';
			payData.orderInfo = data;
		}
		payData.success=function (res) {
			tt.navigateTo({
				url: "/pages/mall/service-mall-success/service-mall-success.vue"
			})
        console.log('success:' + JSON.stringify(res));
		}
		console.log("支付参数", payData);
		uni.requestPayment(payData);
	}, err => {
		callback && callback({
			success: false,
			data: err
		});
	});
}

